﻿Imports System.Object
Imports VSModel
Imports Cls_Common
Partial Class Control_Contents_Detail_Image
    Inherits System.Web.UI.UserControl
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            If Not Request.QueryString("Id") Is Nothing Then
                hidID.Value = Request.QueryString("Id")
                ShowData()
            End If
        End If
    End Sub
    Protected Sub ShowData()
        Using data As New VSEntities
            Dim p = (From q In data.Contents Where q.Id = hidID.Value And q.TypeId = 4 Select q).SingleOrDefault
            If Not p Is Nothing Then
                hplTitle.Text = IIf(IsNothing(p.Title) = True, "", p.Title)
                'ltrDes.Text = IIf(IsNothing(p.Description) = True, "", p.Description)
                imgNews.ImageUrl = p.Image.ToString.Replace("~/Uploads", "")
                lblAuthor.Text = p.Author.ToString
                lblCreated.Text = String.Format("{0:d/M/yyyy}", p.Created)
                hplType.Text = arrTypeText(p.TypeId)
                hplType.CssClass = arrTypeCssClass(p.TypeId)
                Dim t = (From q In data.Albums Where q.ContensID = hidID.Value Select q).ToList
                ltrContent.Text = ""
                For Each k As Album In t
                    ltrContent.Text += "<div><img src=""" + k.ImageUrl.ToString + """  style=""width: 260px; height: 220px; top: 0px; left: 0px;""> </div><br/><div> " + IIf(IsNothing(k.Title) = True, "", k.Title.ToString) + "  </div><br>"
                Next
                ltrView.Text = "Lượt xem " & IIf(IsNothing(p.Viewed), 0, p.Viewed).ToString
            End If
            Dim h = (From k In data.Contents Where k.MenuId = p.MenuId And k.TypeId = 4 And k.Id <> p.Id And k.TypeId = 4 Select k.Id, k.Title, k.Created, k.TypeId Order By Id Descending).Take(5).ToList
            If Not h Is Nothing Then
                grvData.DataSource = h
                grvData.DataBind()
            End If
        End Using
    End Sub
End Class
